
<!doctype html>
<html>
<head>
    <title>{$data.cate_name}</title>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
    <meta name="format-detection" content="telephone=no"/> <!--禁止数字串在ok手机中被识别成电话号码-->
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no" name="viewport">
    <!-- ICO -->

    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/mobile/main.css" media="all" />
    <link rel="stylesheet" type="text/css" href="__PUBLIC__/css/mobile/style.css" media="all" />
    <!-- iconfont图形样式 -->
    <link rel="stylesheet" href="__PUBLIC__/css/mobile/iconfont/iconfont.css" type="text/css">
    <style type="text/css">
        .btn-primary {
            color: #fff;
            background-color: #43ac43;
            border: 1px solid rgba(0,0,0,0.05);
        }
        .tohide{display: none;}

    </style>
</head>
<body>
<div class="main">
<!--header页头文件开始-->
    <div class="header">
        <p><strong>{$data.name}</strong></p>
        <input type="hidden" name="id" id="deviceId" value="{$data.id}">
    </div><!--header页头文件结束-->
    <!--mainBody文件开始-->
    <div class="mainbody">
        <p class="red size">请认真填写，谢谢！</p>
        <div class="items clear">
            <div class="left item"><!--左边设备情况表-->
                <p class="tiem-font-size">设备情况</p>
                <div class="item-input">
                    <foreach name="status" item="st">
                        <input type="checkbox" class="device_status" id="OneSt{$st.id}" data-next={$st.is_next} name="{$st.id}" value="{$st.id}" onclick="two_status(this)">&nbsp;{$st.status_name}
                    <br>
                    </foreach>
                </div>
                <br>
                <div class="item-sm">
                    <p>说明：可以同时勾选多项，异常和正常不能同时勾选</p>
                </div>
            </div>
            <div class="right item"><!--右边捕获情况表-->
                <p class="tiem-font-size">捕获情况</p>
                <div class="item-table">
                    <table class="table-catch">
                        <tr class="">
                            <th>种类</th>
                            <th>数量</th>
                        </tr>
                        <foreach name="pest_name" item="pn">
                            <tr>
                                <td>{$pn.name}</td>
                                <td><input type="text" class="pest" data-id="{$pn.id}" name="{$pn.id}" placeholder="0" value=""></td>
                            </tr>
                        </foreach>
                    </table>
                </div>
            </div>
        </div>
    </div><!--mainBody文件结束-->

</div>
<div class="high40" style="height:40px;width: 100px;">
	ad
</div>
<!--footer底部文件-->
<div class="device-foot clear">
    <a id="submit" onclick="submitData()" class="btn btn-primary">提交</a>
</div>
<script src="__PUBLIC__/js/jquery-1.10.1.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/js/jquery-migrate-1.2.1.min.js" type="text/javascript"></script>
<script src="__PUBLIC__/plugins/layer/layer.min.js"></script>
<script type="text/javascript">
    function two_status(obj){
        var is_choose = $(obj).attr('checked');
        //判断正常和异常，两个不能同时选择
        if (is_choose == 'checked'){
            var this_id = $(obj).attr('id');
            
            //如果当前的id值为one0，则为正常情况，先判断异常one1是否已经选中
            if (this_id == "one0") {
                //检查异常项是否被选中
                var one1 = $("#one1").attr("checked");
                if (one1 == 'checked') {
                    $(obj).removeAttr('checked');
                    layer.msg("正常异常不能同时选择");
                    return false;
                }
            }
            //如果当前的id值为one1，则为异常情况情况，先判断异常one0是否已经选中
            if (this_id == "one1") {
                //检查异常项是否被选中
                var one0 = $("#one0").attr("checked");
                if (one0 == 'checked') {
                    $(obj).removeAttr('checked');
                    layer.msg("正常异常不能同时选择");
                    return false;
                }
            }
        }
        if (is_choose == 'checked') {
            var is_next = $(obj).attr('data-next')
            if (is_next == 1) {
                var id = $(obj).attr("name");
                var url = '__MODULE__/Light/status_2/id/' + id;
                layer.open({
                      type: 2,
                      area: ['90%', '60%'],
                      fixed: false, //不固定
                      maxmin: true,
                      content: url
                });
            }
            return false;
        }
    };
    function submitData(){
        //记录设备状态
        deviceStatus = {};
        $("input.device_status").each(function(){
            //查看当前设备状态是否被选中
            if (this.checked) {
                //如果有下一级状态，将下一级状态的获取到
                if ($(this).attr('data-next') == '1') {
                    deviceStatus[this.name] =JSON.parse(unescape(this.value));
                    console.log(deviceStatus[this.name])
                }else{
                    //如果设备没有下一级状态，直接将转态值设为1
                    deviceStatus[this.name] = 1;
                }
            }
        });
        
        //记录捕获飞虫的数量
        pestData = {};
        $("input.pest").each(function(){
            if (this.value != "") {
                pestData[this.name] = this.value;
            }
        });
        postData = {};
        postData['id'] = $("#deviceId").val();
        postData['status'] = deviceStatus;
        postData['animal'] = pestData;
        var url = "{:U('Light/add')}";
        $.post(url,postData,function(result){
            if (result.status == 1) {
                layer.msg('成功');
                return false;
            }
        },"JSON");
        return false;
    }
    function checkCookies(){
        pestData = {};
        $("input.pest").each(function(){
            if (this.value != "") {
                pestData[this.name] = this.value;
            }
        });
        testData = {};
        testData['1'] = pestData;
        testData['2'] = pestData;
        console.log(testData);
        console.log(unescape(escape(JSON.stringify(testData))));
        console.log(JSON.stringify(pestData))
    }

</script>
</body>
</html>